class Solution(object):
    def countMaxOrSubsets(self, nums):
        n = len(nums)
        self.max_val = 0
        self.max_num = 0

        def cal(val):
            base = 0
            for i in range(n):
                if (val >> i) & 1:
                    base |= nums[i]
            if base > self.max_val:
                self.max_val = base
                self.max_num = 1
            else:
                if base == self.max_val:
                    self.max_num += 1

        for val in range(1, 2 ** n):
            cal(val)

        return self.max_num

data = Solution()
nums = [3, 1]
print(data.countMaxOrSubsets(nums))